<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>
<%@ include file="include/includetag.jsp" %>

<div class="bjui-pageContent">
    <form class="content-bottom">
            <table>
                <tbody>
                <tr>
                    <td class="td-first-child"><span>用户名：</span></td>
                    <td class="td-last-child"><input id="username" type="text" value="admin" name="" style="float: left" placeholder="请输入用户名" autocomplete="off"></td>
                </tr>
                <tr>
                    <td class="td-first-child"><span>密<span style="padding-left: 14px;"></span>码：</span></td>
                    <td class="td-last-child"><div><input id="password" type="password" value="123456" name="" style="float: left" placeholder="请输入密码" autocomplete="off"></div></td>
                </tr>
                <tr>
                    <td class="td-first-child"><span>验证码：</span></td>
                    <td class="td-last-child">
                        <div class="verification-code">
                            <input id="imagecode" type="text" name="" placeholder="请输入验证码" autocomplete="off">
                            <div>
                            <img id="getcode" onclick="get_img_code()" style="width: 100%;height: 100%;" alt="验证码"/>
                        </div>

                    </td>
                </tr>
                </tbody>
            </table>
        </form>
</div>
<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-close" data-icon="remove">取消</button></li>
        <li><button type="button" onclick="Dologin()" class="btn-default" data-icon="check">登录</button></li>
    </ul>
</div>
<script type="text/javascript">
$(function(){
    get_img_code();
})
function get_img_code(){
        var img = document.getElementById("getcode");
        var randomnum = Math.random();
        img.src="/account/getVerifyimg?"+randomnum;
    }
    
    function Dologin() {
        var username = $('#username').val();
        var password = $('#password').val();
        var imagecode = $('#imagecode').val();
        if (username == "") {
            BJUI.alertmsg('info', "请输入登录帐号");
            return;
        }
        if (password == "") {
            BJUI.alertmsg('info', "请输入登录密码");
            return;
        }
        if (imagecode == "") {
            BJUI.alertmsg('info', "请输入验证码");
            return;
        }
        $.ajax({
                 type: "post",
                 async: false,
                 url: "/login",
                 dataType:'json',
                 "data":{
                    "usercode":username,
                    "pwd":password,
                    'vcode':imagecode
                 },
                 success:function(msg){
                    if(msg.statusCode=="200"){
                        location.href = "/";
                    }else{
                        BJUI.alertmsg('info', msg.message);
                        get_img_code();
                    }
                 },
                 error:function(XMLHttpRequest, textStatus, errorThrown){
                    if(XMLHttpRequest.status){
                        location.href = "/severError";
                    }
                 }
        });
    }
</script>